//
//  MainViewController.swift
//  sinaweibo
//
//  Created by ma c on 16/3/6.
//  Copyright © 2016年 ower. All rights reserved.
//

import UIKit

class MainViewController: UITabBarController {
    
    //外界跳转页面 和外界调用的方法 写到类的最顶层
    
@objc private   func plusBtnDidClick() {
        print(__FUNCTION__)
        print("=====")
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        
        let mainTabbar = MainTabBar()
        mainTabbar.plusBtn.addTarget(self, action: "plusBtnDidClick", forControlEvents: .TouchUpInside)
        //添加所有的子视图
        addChildViewControllers()
        
        //KVC 给对象提供类似字典的方式 访问对象的属性
        setValue(mainTabbar, forKey: "tabBar")
        
        //print(tabBar.classForCoder) 打印当前类信息.classForCoder
    }
    private func addChildViewControllers() {
        addChildViewController(HomeTableViewController(), title: "首页", imagename: "tabbar_home")
        addChildViewController(MessageTableViewController(), title: "消息", imagename: "tabbar_message_center")
        addChildViewController(DiscoverTableViewController(), title: "发现", imagename: "tabbar_discover")
        addChildViewController(ProfileTableViewController(), title: "我", imagename: "tabbar_profile")
        
    }
    
    //Mark: 添加子视图控制器
    private func addChildViewController(vc: UIViewController,title: String, imagename:String) {
        vc.navigationItem.title = title
        vc.tabBarItem.title = title
        //设置title
        //vc.title = title
        
        //设置tintColor
        //tabBar.tintColor = UIColor.orangeColor()
        //设置图片
        vc.tabBarItem.image = UIImage(named: imagename)
        //设置字体颜色
        vc.tabBarItem.setTitleTextAttributes([NSForegroundColorAttributeName : UIColor.orangeColor()], forState: .Selected)
        //设置选中图片
        vc.tabBarItem.selectedImage = UIImage(named: imagename + "_selected")?.imageWithRenderingMode(.AlwaysOriginal)
        
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    
}
